package library.sdk.demo.activity;

import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;

import java.lang.ref.WeakReference;
import java.util.LinkedHashMap;

import algorithm.TestKalmanActivity;
import library.sdk.demo.MainApplication;
import library.sdk.demo.R;
import library.sdk.demo.activity.module.m1.M1Activity;
import library.sdk.demo.activity.module.qbox8.QBox8Activity;
import library.sdk.demo.parent.ParentActivity;
import library.utils.DisplayUtil;
import library.utils.Utils;
import widget.annotation.ViewInject;
import widget.dialog.PopupMenuDialog;
import widget.list.ListView;

public class MainActivity extends ParentActivity {

    @ViewInject(R.id.activity_main_toolbar)
    private Toolbar mToolbar;
    @ViewInject(R.id.activity_main_list_menu)
    private ListView listView;


    @Override
    protected Object inflateView() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView(View decor) {
        setSystemBar();
        setSupportActionBar(mToolbar);
        mToolbar.requestLayout();

        LinkedHashMap<String, View.OnClickListener> menus = new LinkedHashMap<>();
        menus.put("中海达QBox8", onClick -> {
            Utils.startActivity(getApplicationContext(), QBox8Activity.class);
        });
        menus.put("北斗伴侣M1", onClick -> {
            Utils.startActivity(getApplicationContext(), M1Activity.class);
        });
        menus.put("轨迹优化测试", onClick -> {
            Utils.startActivity(getApplicationContext(), TestKalmanActivity.class);
        });

        listView.setItemDecoration(DisplayUtil.dp2px(1), getResources().getColor(R.color.ltgray));
        listView.setAdapter(new PopupMenuDialog.ListMenuAdapter(menus));

        final float SCALE_MIN = 1.F;
        final float SCALE_MAX = .8F;
        ScaleAnimation animation = new ScaleAnimation(
                SCALE_MIN, SCALE_MAX,
                SCALE_MIN, SCALE_MAX,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setDuration(300);
        animation.setRepeatMode(Animation.REVERSE);
        animation.setRepeatCount(Animation.INFINITE);
        mToolbar.startAnimation(animation);
    }


    @Override
    public void onBackPressed() {
        finish();
    }

    @Override
    public void finish() {
        super.finish();
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}

